
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <base href="/">
  <meta charset="utf-8">
  <title>用户中心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
  <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
  <div class="layui-container">
    <a class="fly-logo" href="/">
      <img th:src="${index[0].blogLogo}" alt="layui" width="200" height="40">
    </a>
  </div>
</div>

<div class="layui-container fly-marginTop fly-user-main">
  <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="user">
    <li class="layui-nav-item">
      <a href="/">
        <i class="layui-icon">&#xe609;</i>
        我的主页
      </a>
    </li>
    <li class="layui-nav-item">
      <a href="user/userindex">
        <i class="layui-icon">&#xe612;</i>
        用户中心
      </a>
    </li>
    <li class="layui-nav-item">
      <a href="user/userInfo">
        <i class="layui-icon">&#xe620;</i>
        基本设置
      </a>
    </li>
    <li class="layui-nav-item layui-this">
      <a href="user/listUserBlog">
        <i class="layui-icon">&#xe60a;</i>
        文章管理
      </a>
    </li>
    <li class="layui-nav-item">
      <a href="user/store">
        <i class="layui-icon">&#xe735;</i>
        VIP管理
      </a>
    </li>
    <li class="layui-nav-item">
      <a href="user/order">
        <i class="layui-icon">&#xe63c;</i>
        订单管理
      </a>
    </li>
  </ul>

  <div class="site-tree-mobile layui-hide">
    <i class="layui-icon">&#xe602;</i>
  </div>
  <div class="site-mobile-shade"></div>
  
  <div class="site-tree-mobile layui-hide">
    <i class="layui-icon">&#xe602;</i>
  </div>
  <div class="site-mobile-shade"></div>
  
  
  <div class="fly-panel fly-panel-user" pad20>
    <!--
    <div class="fly-msg" style="margin-top: 15px;">
      您的邮箱尚未验证，这比较影响您的帐号安全，<a href="activate.html">立即去激活？</a>
    </div>
    -->
    <div class="layui-tab layui-tab-brief" lay-filter="user">

      <table id="LAY-user-back-role " class="demo" lay-filter="LAY-user-back-role"></table>
      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除</button>
        </div>
      </script>
      <script type="text/html" id="buttonTpl">
        {{#  if(d.blogStatus == 1){ }}
        <button class="layui-btn layui-btn-xs">已审核</button>
        {{#  } else { }}
        <button class="layui-btn layui-btn-primary layui-btn-xs">审核中</button>
        {{#  } }}
      </script>
      <script type="text/html" id="layuiadmin-app-cont-tagsbar">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>
<footer th:replace="footer::header-fragment"></footer>
<script th:replace="footer::script-fragment"></script>
<script src="layuiadmin/layui/layui.js"></script>
<script>
  layui.cache.page = 'user';
  layui.cache.user = {
    username: '游客'
    ,uid: -1
    ,avatar: 'res/images/avatar/00.jpg'
    ,experience: 83
    ,sex: '男'
  };
  layui.config({
    version: "3.0.0"
    ,base: 'res/mods/'
  }).extend({
    fly: 'index'
  }).use('fly');
  layui.config({
    base: 'layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table','laypage'], function(){

    var table = layui.table;
    var laypage = layui.laypage;
    var form = layui.form;

    //头工具栏事件
    table.on('toolbar(LAY-user-back-role)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);

      switch(obj.event){
        case 'getCheckData':
          var data = checkStatus.data;
          layer.confirm('确定删除吗？', function(index){
            $.ajax({
              url:'admin/deleteBlog',
              data:{"delete":JSON.stringify(data)},
              dataType:'json',
              method:'post',
              success:function (res) {
                if (res.success){
                  layer.msg('删除成功', {
                    offset: '15px'
                    ,icon: 1
                    ,time: 1000
                  });
                }else {
                  layer.msg('删除失败', {
                    offset: '15px'
                    ,icon: 1
                    ,time: 1000
                  });
                }
              }
              ,error: function(){
                layer.alert('系统错误，请联系管理员！', {
                  icon: 2,
                  skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                });
              }
            });
            table.reload('LAY-user-back-role');
          });
          //layer.alert(JSON.stringify(data));
          break;
        case 'getCheckLength':
          var data = checkStatus.data;
          layer.msg('选中了：'+ data.length + ' 个');
          break;
        case 'isAll':
          layer.msg(checkStatus.isAll ? '全选': '未全选');
          break;

              //自定义头工具栏右侧图标 - 提示
        case 'LAYTABLE_TIPS':
          layer.alert('这是工具栏右侧自定义的一个图标按钮');
          break;
      };
    });
    table.render({
      elem: '.demo'
      ,url: 'admin/allUserBlog',
      page: true //开启分页
      ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      ,defaultToolbar:false

      ,title: '用户数据表'
      ,cols: [
        [
          {type: 'checkbox',width:40},
          {field:'blogId', title:'文章ID', width:80,align:'center',unresize:true},
          {field:'blogTitle', title:'文章标题', width:120,align:'center',unresize:true},
          {field:'blogClassifyName', title:'文章分类', width: 90,align:'center',unresize:true},
          {field:'blogCreateTime', title:'创建时间', width:160,align:'center',unresize:true,templet: "<div>{{layui.util.toDateString(d.blogCreateTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
          {field:'blogUpdateTime', title:'修改时间', width:160,align:'center',unresize:true,templet: "<div>{{layui.util.toDateString(d.blogUpdateTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
          {field:'right', title:'发布状态',toolbar:'#buttonTpl',unresize:true, width:100,align:'center',unresize: true},
          {field:'right', title:'操作',toolbar:'#layuiadmin-app-cont-tagsbar',unresize:true, align:'center',width: 155}
        ]
      ]
      ,limits: [5,10,20,50]  //每页条数的选择项，默认：[10,20,30,40,50,60,70,80,90]。
      ,limit: 5 //每页默认显示的数量
      ,parseData: function(res) { //res 即为原始返回的数据
        return {
          "code": 0, //解析接口状态
          "msg": "", //解析提示文本
          "count": res.count,
          data: res.data.items //解析数据列表
        };
      }
    });

    form.on('switch(Status)', function(obj){
      var blogId = this.value;
      var blogstatus = obj.elem.checked?1:0;
      //请求接口
      $.post('admin/updateBlogStatus',{
        "blogId":blogId,
        "blogstatus":blogstatus
      },'json');
    });


    //执行一个laypage实例
    laypage.render({
      elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
      ,count: 50 //数据总数，从服务端得到
    });
    var $ = layui.$, active = {
      add: function(){
        layer.open({
          type: 2
          ,title: '添加分类'
          ,content: 'admin/addBlogs'
          ,maxmin: true
          ,area: ['1300px', '600px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
                    ,tags = othis.find('input[name="tags"]').val();
            //请求接口
            $.post('admin/addClassify',{
              "tags":tags
            },function (res){
              if (res.success){
                layer.msg('添加分类成功', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }else {
                layer.msg('添加分类失败', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }
            },'json');
            if(!tags.replace(/\s/g, '')) return;

            table.reload('LAY-user-back-role');
            layer.close(index);
          }
        });
      }
    }

    $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    //监听行工具栏
    table.on('tool(LAY-user-back-role)',function (obj) {
      //获取行数据
      var data = obj.data;
      //点击删除
      if (obj.event === 'del'){
        layer.confirm('确定删除吗？', function(index){
          $.ajax({
            url:'admin/deleteByIdBlog',
            data:{"blogId":data.blogId},
            dataType:'json',
            method:'post',
            success:function (res) {
              if (res.success){
                layer.msg('删除成功', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }else {
                layer.msg('删除失败', {
                  offset: '15px'
                  ,icon: 1
                  ,time: 1000
                });
              }
              table.reload('LAY-user-manage');
            }
            ,error: function(){
              layer.alert('系统错误，请联系管理员！', {
                icon: 2,
                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
              });
            }
          });
          layer.close(index);
        });
        //删除方法
      } else if (obj.event === 'edit'){
        //点击编辑
        location.href = 'user/editBlog?blogId='+data.blogId; //跳转到后台首页
      }
    })
    table.reload('LAY-user-back-role');
  });
</script>

</body>
</html>